package Server;

import java.io.IOException;
import java.net.*;
import java.security.acl.Group;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Martin Strouhal
 */
public class MulticastServerThread extends Thread {

    private boolean dalsiPozadavky = true;

    @Override
    public void run() {
        DatagramSocket socket = null;
        try {
            socket = new DatagramSocket(4466);
        } catch (SocketException ex) {
            System.out.println(ex);
        }
        while (dalsiPozadavky) {
            String stringName = "TOTNE";
            byte[] byteName = stringName.getBytes();
            InetAddress group = null;
            try {
                group = InetAddress.getByName("203.0.113.0");
            } catch (UnknownHostException ex) {
                System.out.println(ex);
            }
            DatagramPacket packet = new DatagramPacket(byteName, byteName.length, group, 4466);
            try {
                socket.send(packet);
            } catch (IOException ex) {
                System.out.println(ex);
            }
            try {
                sleep(5000);
            } catch (InterruptedException ex) {
                System.out.println(ex);
            }
        }
        socket.close();
    }

    void setDalsiPozadavky(boolean b) {
        dalsiPozadavky = b;
    }
}
